#include "widget.h"
#include "ui_widget.h"

#include <QFile>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    showLbPicture();
    showTextBrose();
    ui->progressBar->setRange(0,1000000);
    ui->progressBar->setValue(0);

//    ui->lcdnum
    time=new QTimer(this);
    time->setInterval(1000);//以一秒作为间隔
    connect(time,&QTimer::timeout,this,&Widget::slotTime);


}

Widget::~Widget()
{
    delete ui;
}

void Widget::showLbPicture()
{

    QString picture("D:\\job\\qt\\work\\me\\day1\\3.png");
    QImage img;

    if(!(img.load(picture)))
    {
        QMessageBox::information(NULL,"失败","加载jpg图片失败，请重新检查?");
        return;
    }
    ui->labeljpg->setPixmap(QPixmap::fromImage(img).scaled(ui->labeljpg->width(),ui->labeljpg->height()));

}

void Widget::showTextBrose()
{
    QString qstrDate;
    QFile file("D:\\job\\qt\\work\\me\\day1\\csdn2.txt");
    bool ok=file.open(QIODevice::ReadOnly|QIODevice::Text);
    if(ok==false)
    {
        QMessageBox::warning(this,"失败","打开文件失败，请重新检查?");
        return;

    }
    while(!file.atEnd())
    {
        QByteArray line = file.readLine();
        QString strs(line);
        qstrDate.append(strs);


    }
    ui->textBrowser->setText(qstrDate);

}


void Widget::on_pushButton_4_clicked()
{
    int i=0;
    while (i<1000000) {
        i++;
        ui->progressBar->setValue(i);

    }
}

void Widget::on_startBtn_clicked()
{
    time->start();


    ui->startBtn->setEnabled(false);
    ui->pauseBtn->setEnabled(true);
    ui->resertBtn->setEnabled(true);

}

void Widget::on_pauseBtn_clicked()
{
    time->stop();
    ui->startBtn->setEnabled(true);
    ui->pauseBtn->setEnabled(false);
    ui->resertBtn->setEnabled(true);
}

void Widget::on_resertBtn_clicked()
{
    time->stop();
    ui->startBtn->setEnabled(true);
    ui->pauseBtn->setEnabled(true);
    ui->resertBtn->setEnabled(false);
    ui->lcdnum->display(0);
}

void Widget::slotTime()
{
    static int a=0;
    a++;
    ui->lcdnum->display(a);
}
